package com.mDigitalHealth.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

import com.mDigitalHealth.R;
import com.mDigitalHealth.chart.ChartStepEasy;
import com.mDigitalHealth.common.Utils;

public class MainActivityGroup extends TabActivity {

	private static TabHost tabHost;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.main_activity_group);
		initViews();

	}

	private void initViews() {
		// tabHost = (TabHost) findViewById(R.id.tabhost);

		tabHost = getTabHost();
		tabHost.setup(this.getLocalActivityManager());

		tabHost.addTab(tabHost.newTabSpec("tab1")
				.setIndicator("运动", getResources().getDrawable(R.drawable.ic_tab_mysport))
				.setContent(new Intent(this, SportActivity.class)));

		tabHost.addTab(tabHost.newTabSpec("tab2")
				.setIndicator("社区", getResources().getDrawable(R.drawable.ic_tab_friend_and_me))
				.setContent(new Intent(this, WebViewActivity.class)));
		// .setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)));

		// tabHost.addTab(tabHost
		// .newTabSpec("tab3")
		// .setIndicator("消息", getResources().getDrawable(R.drawable.ic_tab_message))
		// .setContent(
		// new Intent(this, MessageActivity.class)
		// .setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)));
		tabHost.addTab(tabHost.newTabSpec("tab4")
				.setIndicator("步数趋势图", getResources().getDrawable(R.drawable.ic_tab_message))
				.setContent(new Intent(this, ChartStepEasy.class)));
		// .setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)));

		tabHost.addTab(tabHost.newTabSpec("tab5")
				.setIndicator("更多", getResources().getDrawable(R.drawable.ic_tab_more))
				.setContent(new Intent(this, Settings.class)));
		tabHost.setBackgroundColor(BIND_AUTO_CREATE);
		// tabHost.set

		tabHost.setCurrentTab(0);

		/*tabHost.setOnTabChangedListener(new OnTabChangeListener() {

			@Override
			public void onTabChanged(String tabId) {
				System.out.println("*******tabId=" + tabId);
				// 如果是tab1拨号
				if (tabId.equals("tab1")) {
					if(RecentCallLogActivity.mLinearLayoutDialPanel != null){
						RecentCallLogActivity.mLinearLayoutDialPanel.setVisibility(RecentCallLogActivity.mLinearLayoutDialPanel.getVisibility() ^ android.view.View.GONE);
					}
				}
			}
		});*/

		/*tabHost.getTabWidget().getChildAt(0).setOnClickListener(new OnClickListener() { 
		    @Override 
		    public void onClick(View v) { 
		    	System.out.println("*********recent call log click******");
		    	if(RecentCallLogActivity.mLinearLayoutDialPanel != null){
		    		if(RecentCallLogActivity.mLinearLayoutDialPanel.getVisibility() == View.VISIBLE)
					{
						RecentCallLogActivity.mLinearLayoutDialPanel.setVisibility(View.GONE);
					}
					else {
						RecentCallLogActivity.mLinearLayoutDialPanel.setVisibility(View.VISIBLE);
					}
		    	}
		    	else{
		    		RecentCallLogActivity.mLinearLayoutDialPanel.setVisibility(View.VISIBLE);
		    	}
		    	tabHost.setCurrentTab(0);
		    } 
		}); */

		// 添加tab切换监听
		// tabHost.setOnTabChangedListener(new tabChange());
	}

	/**
	 * 
	 * <pre>
	 * 业务名:tab切换监听
	 * 功能说明: tab切换监听
	 * 编写日期:	2012-3-12
	 * 作者:	Administrator
	 * </pre>
	 */
	class tabChange implements OnTabChangeListener {

		@Override
		public void onTabChanged(String tabId) {

			String healthURL = Utils.COMMUNITY_URL;
			String videoURL = Utils.VIDEO_URL;
			Intent intent = new Intent();
			// web
			if (tabId.equals("tab2")) {

				Log.d(this.getClass().getName(), "go to MediaPlayerActivity");
				intent.putExtra("url", healthURL);
				intent.setClass(MainActivityGroup.this, CommunityActivity.class);

				// video
			} else if (tabId.equals("tab4")) {
				Log.d(this.getClass().getName(), "go to mediaPlay");
				intent.putExtra("path", videoURL);
				intent.setClass(MainActivityGroup.this, VideoViewActivity.class);
			}

			startActivity(intent);
		}

	}
}